/* GUI CONVERTED from rcrp16.p (converter v1.75) Sat Aug 12 23:00:25 2000 */
/* rcrp16.p - PLAN TO SHIP SCHEDULE VARIANCE REPORT                     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*V8:ConvertMode=FullGUIReport                                          */
/* REVISION: 9.1   CREATED       : 10/13/99     BY: *N004* Steve Nugent */
/* REVISION: 9.1   LAST MODIFIED: 03/24/00      BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1   LAST MODIFIED: 08/12/00      BY: *N0KP* myb              */


/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

          {mfdtitle.i}


/* **************** Begin Translatable Strings Definitions **************** */

         &SCOPED-DEFINE rcrp16_p_1 "Variance % "
         /* MaxLen:18: Comment: Variance percentage.*/

         &SCOPED-DEFINE rcrp16_p_2 "ABC Class"
         /* MaxLen:20 Comment: Relates to the ABC Class field in the Item
                               Master. This class designates the importance
                               of an item. */

         &SCOPED-DEFINE rcrp16_p_3 "Plan Release ID"
         /* MaxLen:20 Comment: The Planning or Shipping schedule release ID */

         &SCOPED-DEFINE rcrp16_p_4 "Ship Release ID"
         /* MaxLen:20 Comment: Sequence Schedule release ID */

         &SCOPED-DEFINE rcrp16_p_5 "Plan Discrete Qty!Ship Discrete Qty"
         /* MaxLen:20 Comment: The Shipping or Planning quantity and the Sequence
                             schedule quantity. */

         &SCOPED-DEFINE rcrp16_p_6 "Plan Cum Qty!Ship Cum Qty"
         /* MaxLen:16 Comment: The Shipping or Planning cumulative quantity and
                             the Sequence Schedule cumulative quantity. */

         &SCOPED-DEFINE rcrp16_p_7 "Order"
         /* MaxLen:20 Comment: The sequence schedule sales order. */

         &SCOPED-DEFINE rcrp16_p_8 "Ship-From"
         /* MaxLen:20 Comment:  The sequence schedule ship-from address. */

         &SCOPED-DEFINE rcrp16_p_9 "Qty Diff"
         /* MaxLen:12 Comment: Quantity difference. */

         &SCOPED-DEFINE rcrp16_p_10 "Cum Qty Diff"
         /* MaxLen:12 Comment: Cumulative quantity difference. */

         &SCOPED-DEFINE rcrp16_p_11 "Ship-From!Ship-To"
         /* MaxLen:9 Comment: Column-label for the ship-from and ship-to for
                             the sequence scheduled order. */

         &SCOPED-DEFINE rcrp16_p_12 "Order!Line"
         /* MaxLen:8 Comment: Column-label for the sales order and line for
                             the sequence schedule. */

         &SCOPED-DEFINE rcrp16_p_13 "Plan Release ID!Ship Release ID"
         /* MaxLen:18 Comment: The shipping and planning release IDs for the
                             reported schedule */

/* ***************** End Translatable Strings Definitions ******************* */

         
         


         define variable wk_plan_date  like schd_date no-undo.
         define variable wk_plan_rlid  like sch_rlse_id no-undo.
         define variable wk_ship_rlid  like sch_rlse_id no-undo.
         define variable diff_qty      like ld_qty_oh label
                                                     {&rcrp16_p_9} no-undo.
         define variable cum_diff_qty  like ld_qty_oh label
                                                     {&rcrp16_p_10} no-undo.
         define variable so_from       like so_nbr no-undo.
         define variable so_to         like so_nbr no-undo.
         define variable var_variance  as  decimal
            format "99" label {&rcrp16_p_1} no-undo.
         define variable var_percent_qty  as  decimal
            format "ZZZ99" label {&rcrp16_p_1} no-undo.
         define variable var_percent_cum  as  decimal
            format "ZZZ99" label {&rcrp16_p_1} no-undo.
         define variable wk_percent_qty as decimal format "999.99" no-undo.
         define variable wk_percent_cum as decimal format "999.99" no-undo.
         define variable wk_variance   as decimal format ".99" no-undo.
         define variable var_abc_class as  character
            format "x(1)" label {&rcrp16_p_2} no-undo.
         define variable wk_del_flag   like mfc_logical no-undo.
         define variable wk_delta      like schd_discr_qty no-undo.
         define variable wk_upper_lmt  like schd_discr_qty no-undo.
         define variable wk_lower_lmt  like schd_discr_qty no-undo.
         define variable part_from     like sod_part no-undo.
         define variable part_to       like sod_part no-undo.
         define variable shipto_from   like so_ship no-undo.
         define variable shipto_to     like so_ship no-undo.
         define variable shipfrom_from like scx_shipfrom no-undo.
         define variable shipfrom_to   like scx_shipfrom no-undo.
         define variable plan_schd_discr_qty
                                       like schd_discr_qty no-undo.
         define variable ship_schd_discr_qty
                                       like schd_discr_qty no-undo.




         define temp-table ship_schd_day no-undo
                field ssd_nbr       like so_nbr
                field ssd_line      like schd_line
                field ssd_date      like schd_date
                field ssd_part      like sod_part
                field ssd_desc      like pt_desc1
                field ssd_plan_rlid like schd_rlse_id label {&rcrp16_p_3}
                field ssd_ship_rlid like schd_rlse_id label {&rcrp16_p_4}
                field ssd_plan_flag as logical
                field ssd_ship_flag as logical
                field ssd_plan_qty  like schd_discr_qty label {&rcrp16_p_5}
                field ssd_ship_qty  like schd_discr_qty label {&rcrp16_p_6}
                field ssd_plan_cum  like schd_cum_qty
                field ssd_ship_cum  like schd_cum_qty
                field ssd_fc_qual   like schd_fc_qual
                field ssd_interval  like schd_interval
                field ssd_cum_qty   like schd_cum_qty
                field ssd_pct_qty   as decimal
                                    format "ZZZ99"
                                    label {&rcrp16_p_1}
                field ssd_pct_cum   as decimal
                                    format "ZZZ99"
                                    label {&rcrp16_p_1}
                field ssd_shipfrom  like scx_shipfrom
                field ssd_shipto    like scx_shipto
                index ssd_index1    is unique primary
                                    ssd_nbr
                                    ssd_line
                                    ssd_date.

        
/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
           
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
shipfrom_from        colon 22 label {&rcrp16_p_8}
           shipfrom_to          colon 50 label {t001.i}
           shipto_from          colon 22
           shipto_to            colon 50 label {t001.i}
           part_from            colon 22
           part_to              colon 50 label {t001.i}
           so_from              colon 22 label {&rcrp16_p_7}
           so_to                colon 50 label {t001.i}
           shipto_from          colon 22
           shipto_to            colon 50 label {t001.i}
           skip (1)
           var_variance         colon 22
           var_abc_class        colon 22
         SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



        /* SET EXTERNAL LABELS */
        setFrameLabels(frame a:handle).

         {wbrp01.i}
         
/*GUI*/ {mfguirpa.i true  "printer" 132 }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:

            display
              var_variance with frame a.

            if shipfrom_to = hi_char then shipfrom_to = "".
            if shipto_to = hi_char then shipfrom_to = "".
            if so_to   = hi_char then so_to = "".
            if part_to = hi_char then part_to = "".
            if shipto_to = hi_char then shipto_to = "".

            if c-application-mode <> 'WEB':U then
               
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:


            {wbrp06.i &command = update
                      &fields = "shipfrom_from shipfrom_to shipto_from
                                 shipto_to part_from part_to so_from so_to
                                 var_variance var_abc_class"
                      &frm = "a"}

             if (c-application-mode <> 'WEB':U)  or
             (c-application-mode = 'WEB':U and
             (c-web-request begins 'DATA':U))
             then do:
                   bcdparm = "".
                   {mfquoter.i shipfrom_from}
                   {mfquoter.i shipfrom_to }
                   {mfquoter.i shipto_from}
                   {mfquoter.i shipto_to }
                   {mfquoter.i part_from   }
                   {mfquoter.i part_to     }
                   {mfquoter.i so_from     }
                   {mfquoter.i so_to       }
                   {mfquoter.i var_variance }
                   {mfquoter.i var_abc_class }

                   if shipfrom_to = "" then shipfrom_to = hi_char.
                   if shipto_to = "" then shipto_to = hi_char.
                   if so_to = "" then so_to = hi_char.
                   if part_to = "" then part_to = hi_char.
                   if shipto_to = "" then shipto_to = hi_char.

             end.  /* do */

           /* SELECT PRINTER */
           
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i  "printer" 132}
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:

define buffer ship_mstr       for sch_mstr.
define buffer ship_det        for schd_det.


           {mfphead2.i}

             /* Main Loop */

             assign
               wk_variance = var_variance / 100.

             for each so_mstr where
                       (so_nbr >= so_from and so_nbr <= so_to) and
                       (so_ship >= shipto_from and so_ship <= shipto_to)
                       no-lock,
                       each sod_det where
                       so_nbr = sod_nbr  and
                       sod_curr_rlse_id[1] <> ''  and
                       sod_curr_rlse_id[2] <> ''  and
                       (sod_part >= part_from and sod_part <= part_to) and
                       (sod_site >= shipfrom_from and sod_site <= shipfrom_to)
                       no-lock,
                       each pt_mstr where
                            pt_part = sod_part no-lock:

                 if var_abc_class <> "" then
                    if pt_abc <> var_abc_class then
                    next.

                 find last sch_mstr where
                         sch_rlse_id = sod_curr_rlse_id[1]
                         and sch_type = 1
                         and sch_nbr = so_nbr
                         and sch_line = sod_line
                         use-index sch_cr_date
                         no-lock no-error.

                 if not available sch_mstr then
                 next.
                 else
                 wk_plan_rlid = sch_rlse_id.

                 find last sch_mstr where
                      sch_rlse_id = sod_curr_rlse_id[2]
                      and   sch_type = 2
                      and   sch_nbr = so_nbr
                      and   sch_line = sod_line
                      use-index sch_cr_date
                      no-lock no-error.

                 if not available sch_mstr then
                 next.
                 else
                 wk_ship_rlid = sch_rlse_id.

                 find last sch_mstr where sch_rlse_id = sod_curr_rlse_id[1]
                                    and sch_type = 1
                                    and sch_nbr = so_nbr
                                    and sch_line = sod_line
                                    use-index sch_cr_date
                                    no-lock no-error.
                 assign plan_schd_discr_qty = 0.

                 for each schd_det
                         where sch_type = schd_type
                         and schd_nbr = sch_nbr
                         and schd_line = sch_line
                         and schd_rlse_id = sch_rlse_id
                         and schd_interval = "W"
                         no-lock
                         break
                         by schd_type
                         by schd_nbr
                         by schd_line
                         by schd_rlse_id
                         by schd_date:

                         assign plan_schd_discr_qty =
                              plan_schd_discr_qty + schd_discr_qty.
                         if last-of (schd_date)
                         then do:

                             for first scx_ref where
                                       scx_type = 1          and
                                       scx_order = schd_nbr  and
                                       scx_line = schd_line no-lock:
                             end.

                             create ship_schd_day.
                             assign
                             ssd_nbr       = schd_nbr
                             ssd_line      = schd_line
                             ssd_date      = schd_date
                             ssd_part      = sod_part
                             ssd_desc      = pt_desc1
                             ssd_plan_rlid = wk_plan_rlid
                             ssd_ship_rlid = wk_ship_rlid
                             ssd_plan_flag = yes
                             ssd_ship_flag = no
                             ssd_plan_qty  = plan_schd_discr_qty
                             ssd_ship_qty  = 0
                             ssd_plan_cum   = schd_cum_qty
                             ssd_fc_qual   = schd_fc_qual
                             ssd_interval  = schd_interval
                             ssd_cum_qty   = schd_cum_qty
                             ssd_shipfrom  = scx_shipfrom
                             ssd_shipto    = scx_shipto
                             plan_schd_discr_qty = 0
                             wk_plan_date = schd_date.
                         end. /* if last-of (schd_date) ..do */

                         find last ship_mstr
                                   where ship_mstr.sch_rlse_id =
                                      sod_curr_rlse_id[2]
                                   and   ship_mstr.sch_type = 2
                                   and   ship_mstr.sch_nbr = so_nbr
                                   and   ship_mstr.sch_line = sod_line
                                   use-index sch_cr_date
                                   no-lock no-error.

                         if available sch_mstr
                         then do:
                            assign ship_schd_discr_qty = 0.

                            for each ship_det
                                 where ship_mstr.sch_type = ship_det.schd_type
                                 and ship_det.schd_nbr = ship_mstr.sch_nbr
                                 and ship_det.schd_line = ship_mstr.sch_line
                                 and ship_det.schd_rlse_id =
                                       ship_mstr.sch_rlse_id
                                 and (ship_det.schd_date >= wk_plan_date
                                      and ship_det.schd_date < wk_plan_date + 7)
                                 no-lock
                                 break
                                 by ship_det.schd_type
                                 by ship_det.schd_nbr
                                 by ship_det.schd_line
                                 by ship_det.schd_rlse_id
                                 by ship_det.schd_date:
                                 assign ship_schd_discr_qty
                                     = ship_schd_discr_qty +
                                       ship_det.schd_discr.
                                 if last-of (ship_det.schd_date)
                                 then do:
                                     for first ship_schd_day
                                        where ssd_nbr       = ship_det.schd_nbr
                                        and   ssd_line      = ship_det.schd_line
                                        and   ssd_date      = wk_plan_date
                                        exclusive-lock:
                                     end. /* for first */
                                     if available ship_schd_day then
                                        assign
                                           ssd_ship_flag  = yes
                                           ssd_ship_qty   = ssd_ship_qty +
                                               ship_schd_discr_qty
                                           ssd_ship_cum = ship_det.schd_cum_qty.

                                     else do:
                                       if ship_schd_discr_qty <> 0
                                       then do:

                                         for first scx_ref where
                                                   scx_type = 1          and
                                                   scx_order =
                                                      ship_det.schd_nbr  and
                                                   scx_line =
                                                      ship_det.schd_line
                                                   no-lock:
                                         end.
                                         create ship_schd_day.
                                         assign
                                         ssd_nbr       = ship_det.schd_nbr
                                         ssd_line      = ship_det.schd_line
                                         ssd_date      = ship_det.schd_date
                                         ssd_part      = sod_part
                                         ssd_desc      = pt_desc1
                                         ssd_plan_rlid = wk_plan_rlid
                                         ssd_plan_qty  = 0
                                         ssd_ship_rlid = wk_ship_rlid
                                         ssd_plan_cum  = 0
                                         ssd_plan_flag = no
                                         ssd_ship_flag = yes
                                         ssd_ship_cum  = ship_det.schd_cum_qty
                                         ssd_ship_qty  = ship_schd_discr_qty
                                         ssd_fc_qual   = ship_det.schd_fc_qual
                                         ssd_interval  = ship_det.schd_interval
                                         ssd_cum_qty   = ship_det.schd_cum_qty
                                         ssd_shipfrom  = scx_shipfrom
                                         ssd_shipto    = scx_shipto.
                                       end. /* if ship_schd_discr_qty <> 0 do */
                                     end. /* else do */
                                  assign ship_schd_discr_qty = 0.
                                 end. /* if last-of (ship_det.schd_date)..do */
                            end. /* for each ship_det */
                        end. /* if available sch_mstr */

                 end. /* for each schd_det */

                for each ship_schd_day exclusive-lock:

                    wk_del_flag = no.
                    if ssd_plan_qty = ssd_ship_qty then
                        wk_del_flag = yes.
                    if not ssd_plan_flag
                    or not ssd_ship_flag then
                        wk_del_flag = yes.
                    if wk_del_flag = no
                    then do:
                        assign
                          wk_delta = ssd_plan_qty * wk_variance
                          wk_upper_lmt = ssd_plan_qty + wk_delta
                          wk_lower_lmt = ssd_plan_qty - wk_delta.

                        if  ssd_ship_qty < wk_upper_lmt
                        and ssd_ship_qty > wk_lower_lmt
                            then wk_del_flag = yes.
                    end. /* do */

                    if wk_del_flag then
                        delete ship_schd_day.
                    else do:
                        assign
                           diff_qty = ssd_plan_qty - ssd_ship_qty
                           cum_diff_qty = ssd_plan_cum - ssd_ship_cum.

                        if diff_qty > 0 then
                            wk_percent_qty = diff_qty / ssd_plan_qty.
                        else
                         assign
                            diff_qty = diff_qty * -1
                            wk_percent_qty = diff_qty / ssd_plan_qty.

                        if ssd_plan_qty = 0 then
                            wk_percent_qty = 1.

                        if cum_diff_qty > 0 then
                            wk_percent_cum = cum_diff_qty / ssd_plan_cum.
                        else
                         assign
                            cum_diff_qty = cum_diff_qty * -1
                            wk_percent_cum = cum_diff_qty / ssd_plan_cum.

                        if ssd_plan_cum = 0 then
                           wk_percent_cum = 1.

                        assign
                           ssd_pct_qty = wk_percent_qty * 100.
                           ssd_pct_cum = wk_percent_cum * 100.
                    end. /* else do */
                end. /* for each ship_schd_day */

                FORM /*GUI*/ 
                with STREAM-IO /*GUI*/  frame ssdhead down width 132 no-box.

                /* SET EXTERNAL LABELS */
                setFrameLabels(frame ssdhead:handle).

                FORM /*GUI*/ 
                with STREAM-IO /*GUI*/  frame ssddet down width 132 no-box.

                /* SET EXTERNAL LABELS */
                setFrameLabels(frame ssddet:handle).

                clear frame ssdhead all no-pause.
                clear frame ssddet all no-pause.

                for each ship_schd_day
                exclusive-lock
                break
                by ssd_shipfrom
                by ssd_shipto
                by ssd_nbr
                by ssd_line
                by ssd_date:
                    if first-of (ssd_line) then do:
                        display
                           ssd_shipfrom column-label {&rcrp16_p_11}
                           ssd_nbr column-label {&rcrp16_p_12}
                           ssd_part
                           ssd_desc
                           ssd_plan_rlid column-label {&rcrp16_p_13}
                           with width 132
                           frame ssdhead STREAM-IO /*GUI*/ .

                           down 1 with frame ssdhead.

                        display
                           ssd_shipto @ ssd_shipfrom
                           ssd_line @ ssd_nbr
                           ssd_ship_rlid @ ssd_plan_rlid
                           with frame ssdhead STREAM-IO /*GUI*/ .

                           down 2 with frame ssdhead.

                    end. /* if first-of (ssd_line).. do */

                    assign
                        diff_qty = ssd_plan_qty - ssd_ship_qty
                        cum_diff_qty = ssd_plan_cum - ssd_ship_cum.

                    display
                        space(10)
                        ssd_date
                        ssd_plan_qty column-label {&rcrp16_p_5}
                        diff_qty when (diff_qty <> 0)
                        ssd_pct_qty when (ssd_pct_qty <> 0)
                        space(8)
                        ssd_plan_cum column-label {&rcrp16_p_6}
                        cum_diff_qty when (cum_diff_qty <> 0)
                        ssd_pct_cum when (ssd_pct_cum <> 0)
                        with width 132
                        frame ssddet STREAM-IO /*GUI*/ .

                        down 1 with frame ssddet.

                    display
                        ssd_ship_qty @ ssd_plan_qty
                        ssd_ship_cum @ ssd_plan_cum
                        with frame ssddet STREAM-IO /*GUI*/ .

                        down 2 with frame ssddet.

                    delete ship_schd_day.
                end. /* for each ship_schd_day */
             end. /* for each so_mstr */

             /* REPORT TRAILER */
             
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

         end.  /* repeat */

         {wbrp04.i &frame-spec = a}

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" shipfrom_from shipfrom_to shipto_from shipto_to part_from part_to so_from so_to var_variance var_abc_class "} /*Drive the Report*/
